package pkg06.excepciones;

import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Finalize {
    public static void main(String[] args) {
        FileWriter fw = null;
        try {
            fw = new FileWriter("c:\\salida.txt");
            fw.write("Linea 1\n");
            fw.write("Linea 2\n");
            fw.flush();
            fw.write("Linea 3\n");
            fw.write("Linea 4\n");
        } catch (IOException ex) {
            Logger.getLogger(Finalize.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                if(fw!=null) {
                    fw.flush();
                    fw.close();
                }
            } catch (IOException ex) {
                Logger.getLogger(Finalize.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
